package com.drg.center.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.drg.center.entity.DrgPatientCaseDiagnosisPO;
import com.drg.center.mapper.DrgPatientCaseDiagnosisMapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class DrgPatientCaseDiagnosisDAO extends BaseDAO<DrgPatientCaseDiagnosisMapper, DrgPatientCaseDiagnosisPO> {

    public DrgPatientCaseDiagnosisPO findMainOne(String caseCode) {
        LambdaQueryWrapper<DrgPatientCaseDiagnosisPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DrgPatientCaseDiagnosisPO::getCaseCode, caseCode);
        queryWrapper.eq(DrgPatientCaseDiagnosisPO::getIsMain, Boolean.TRUE);
        queryWrapper.orderByAsc(DrgPatientCaseDiagnosisPO::getId);
        queryWrapper.last("limit 0,1");
        return getBaseMapper().selectOne(queryWrapper);
    }

    public List<DrgPatientCaseDiagnosisPO> findSecondList(String caseCode) {
        LambdaQueryWrapper<DrgPatientCaseDiagnosisPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DrgPatientCaseDiagnosisPO::getCaseCode, caseCode);
        queryWrapper.eq(DrgPatientCaseDiagnosisPO::getIsMain, Boolean.FALSE);
        queryWrapper.orderByAsc(DrgPatientCaseDiagnosisPO::getId);
        return getBaseMapper().selectList(queryWrapper);
    }

    public List<DrgPatientCaseDiagnosisPO> findMainList(String caseCode) {
        LambdaQueryWrapper<DrgPatientCaseDiagnosisPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DrgPatientCaseDiagnosisPO::getCaseCode, caseCode);
        queryWrapper.eq(DrgPatientCaseDiagnosisPO::getIsMain, Boolean.TRUE);
        queryWrapper.orderByAsc(DrgPatientCaseDiagnosisPO::getId);
        return getBaseMapper().selectList(queryWrapper);
    }
}
